package cn.tedu.boottext51.contorller;

import cn.tedu.boottext51.mapper.EmpMapper;
import cn.tedu.boottext51.vo.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {
    //此注解会创建一个实现了EmpMapper接口的类 并且实例化出一个对象
    //自动装配 required = false 设置为非必须 避免报错
    @Autowired(required = false)
    EmpMapper mapper;

    @RequestMapping("/insert")//前端发过来请求--和前端请求的地址一样
    //每返回值-void    插入数据要传入Emp
    public void insert(Emp emp){
        mapper.insert(emp);
    }

    @RequestMapping("/select")
    public List<Emp> select(){//有返回值但是没有参数传进来
        return mapper.select();
    }

    @RequestMapping("/delete")
    public void delete(int id){
        mapper.delete(id);
    }

    @RequestMapping("/selectById")
    public Emp update(int id){
        return mapper.selectById(id);
    }

    @RequestMapping("/update")
    public void update(Emp emp){
        mapper.update(emp);
    }

}
